﻿using System;
using ETL.Business.Handlers.ProjectHandlers;
using ETL.Business.Models;
using ETL.Common;
using ETL.Common.Logging;
//using ETL.Business.Handlers.ProjectLogHandler;

namespace ETL.Business.Helpers
{
    public class LogOnToTask
    {
        public virtual string Execute(decimal genProjectId, decimal genTaskId, string userId, string userName)
        {
            try
            {
                // Get current project, current task
                ProjectModel curProject = (new GetProject()).Execute(genProjectId);

                // Check whether this project is completed of suspended)
                //if (curProject.ProjectCompleted == true)
                if (curProject.ProjectStatus == "COMPLETED")
                {
                    return Constants.TaskLogonState.Completed;
                }
                //else if (curProject.ProjectSuspended == true)
                if (curProject.ProjectStatus == "SUSPENDED")
                {
                    return Constants.TaskLogonState.Suspended;
                }

                // log on to task
                (new LogOn()).Execute(genProjectId, genTaskId, userName, userId);

                // return success state)
                return Constants.TaskLogonState.Successful;
            }
            catch (Exception ex)
            {
                LogService.Service.Error(ex);
                return Constants.TaskLogonState.Failed;
            }
        }
    }
}